﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using Common.Constants;
using Common.Helper;
using Entities;

namespace DataAccess
{
    public class InterventionDataAccess
    {
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static InterventionDataAccess Instance { get; private set; }

        /// <summary>
        /// Initializes the <see cref="AddressDataAccess" /> class.
        /// </summary>
        static InterventionDataAccess() { Instance = new InterventionDataAccess(); }
        /// <summary>
        /// Extracts the raw data.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns></returns>
        private static Intervention ExtractRawData(IDataRecord dataReader)
        {
            return new Intervention
                       {

                           InterventionId = (Guid)dataReader["InterventionId"],
                           InterventionName = dataReader["InterventionName"].ToString(),
                           IsActive = (bool)dataReader["IsActive"]
                       };
        }
        /// <summary>
        /// Lists the intervention.
        /// </summary>
        /// <returns></returns>
        public Collection<Intervention> ListIntervention()
        {
            var lstIntervention = new Collection<Intervention>();
            var dataReader = SqlHelper.ExecuteReader(ProcedureStores.GetIntervention);
            while (dataReader.Read())
            {
                lstIntervention.Add(ExtractRawData(dataReader));
            }
            return lstIntervention;


        }
    }
}
